import axiosInstance from './axiosInstance';
import { API_PATHS } from './apiConfig';
import toastService from './toastService';
import { UserActivity, ApiResponse } from '../types/anime';

// 获取用户最新活动记录
export const getUserLatestActivities = async (page: number = 1, pageSize: number = 9): Promise<{data: UserActivity[], total: number}> => {
  try {
    const response = await axiosInstance.get<ApiResponse<{data: UserActivity[], total: number}>>(API_PATHS.ACTIVITY.LATEST, {
      params: { page, pageSize }
    });
    
    if (response.data.code !== 200) {
      toastService.error(response.data.msg);
      throw new Error(response.data.msg);
    }
    
    // 直接返回response.data.data，因为后端现在返回的是包含data和total的Map对象
    return response.data.data;
  } catch (error) {
    console.error('获取用户活动记录失败:', error);
    // 降级处理：返回空数据和0总数
    return { data: [], total: 0 };
  }
}